@extends('admin.base')

@section('content')
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form" >
                <div class="layui-input-inline">
                    <input type="text" name="title" id="title" placeholder="请输入小区名称" class="layui-input">
                </div>
                <button class="layui-btn layui-btn-normal" id="searchBtn">搜 索</button>
                <button class="layui-btn layui-btn-danger" id="clearBtn">清空筛选</button>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="sel">选择</a>
                </div>
            </script>
        </div>
    </div>
@endsection

@section('script')
    @can('lease.community')
        <script>
            layui.use(['table'],function () {
                var table = layui.table;
                //用户表格初始化
                var dataTable = table.render({
                    elem: '#dataTable'
                    ,url: "{{ route('admin.community.getCommunity') }}" //数据接口
                    ,page: true //开启分页
                    ,cols: [[ //表头
                        {checkbox: true,fixed: true,hide:true}
                        ,{field: 'title',title: '小区名称'}
                        ,{fixed: 'right', width: 80, align:'center', toolbar: '#options',title:'操作'}
                    ]]
                });
                //监听工具条
                table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                    var data = obj.data //获得当前行数据
                        ,layEvent = obj.event; //获得 lay-event 对应的值
                    if(layEvent === 'sel'){
                        var index = parent.layer.getFrameIndex(window.name);
                        var title = data.title
                        var property_id = data.id
                        var parentFrame = $(window.parent.document);
                        parentFrame.find('#selCommunity').val(title);
                        parentFrame.find('#communityid').val(property_id);
                        parentFrame = $(window.parent.document).find('iframe').get(0);
                        $(parentFrame).contents().find("#selCommunity").val(title);
                        $(parentFrame).contents().find("#communityid").val(property_id);
                        parent.layer.close(index);
                    }
                });
                //搜索
                $("#searchBtn").click(function () {
                    var title = $("#title").val();
                    dataTable.reload({
                        where:{title:title},
                        page:{curr:1}
                    })
                })

                $("#clearBtn").click(function () {
                    window.location.reload()
                })
            })
        </script>
    @endcan
@endsection